# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgname=('texinfo' 'info' 'texinfo-tex')
pkgver=6.0
pkgrel=1
pkgdesc="Utilities to work with and produce manuals, ASCII text, and on-line documentation from a single source file"
arch=('i686' 'x86_64')
url="http://www.gnu.org/software/texinfo/"
license=('GPL3')
makedepends=('ncurses-devel' 'gettext-devel' 'findutils' 'gzip' 'perl')
source=(ftp://ftp.gnu.org/pub/gnu/${pkgname}/${pkgname}-${pkgver}.tar.xz{,.sig}
        0001-texinfo-5.1-msys2.patch
        0002-manifest.all.patch
        0003-be-content-with-older-gettext.msys2.patch
        0004-no-w32-stuff.msys2.patch
        0005-fix-makeinfo-exeext.msys2.patch)
md5sums=('02818e62a5b8ae0213a7ff572991bb50'
         'SKIP'
         '96ac50ef1e9c0d65c7f567da7a414ab8'
         '7f4e9eced1af0abfbbf92d64d358c0b4'
         '2c498e6fda118db6cd13727b32ba5bf3'
         '743746cd114e42f85fa6b74b017d4921'
         'ac23191cd53eb9326657573c020ca6ef')

prepare() {
  cd ${srcdir}/${pkgname}-${pkgver}
  patch -p1 -i ${srcdir}/0001-texinfo-5.1-msys2.patch
  patch -p1 -i ${srcdir}/0002-manifest.all.patch
  #patch -p1 -i ${srcdir}/0003-be-content-with-older-gettext.msys2.patch
  patch -p1 -i ${srcdir}/0004-no-w32-stuff.msys2.patch
  patch -p1 -i ${srcdir}/0005-fix-makeinfo-exeext.msys2.patch

  autoreconf -fi
}

build() {
  cd ${srcdir}/${pkgname}-${pkgver}
  ./configure --build=${CHOST} \
    --prefix=/usr \
    --without-libiconv-prefix \
    --without-libintl-prefix \
    gl_cv_func_wcwidth_works=yes

  make
  make DESTDIR=${srcdir}/dest install
}

check() {
  cd ${srcdir}/${pkgname}-${pkgver}
  make check
}

package_texinfo() {
  depends=('info' 'perl' 'sh')
  groups=('base-devel')
  install=texinfo.install

  mkdir -p ${pkgdir}/usr/bin
  mkdir -p ${pkgdir}/usr/share/info
  mkdir -p ${pkgdir}/usr/share/man/man{1,5}
  for ff in makeinfo pod2texi texi2any; do
    cp -f ${srcdir}/dest/usr/bin/${ff} ${pkgdir}/usr/bin/${ff}
    cp -f ${srcdir}/dest/usr/share/man/man1/${ff}.1 ${pkgdir}/usr/share/man/man1/${ff}.1
  done
  cp -rf ${srcdir}/dest/usr/share/locale ${pkgdir}/usr/share/
  cp -rf ${srcdir}/dest/usr/share/texinfo ${pkgdir}/usr/share/
  cp -f ${srcdir}/dest/usr/share/man/man5/texinfo.5 ${pkgdir}/usr/share/man/man5/
  cp -f ${srcdir}/dest/usr/share/info/texinfo.info{,-1,-2,-3} ${pkgdir}/usr/share/info/
}

package_info() {
  depends=('ncurses' 'libintl' 'gzip')
  groups=(base)
  install=info.install

  mkdir -p ${pkgdir}/usr/{bin,share}
  mkdir -p ${pkgdir}/usr/share/info
  mkdir -p ${pkgdir}/usr/share/man/man{1,5}
  for ff in info install-info; do
    cp -f ${srcdir}/dest/usr/bin/${ff}.exe ${pkgdir}/usr/bin/${ff}.exe
    cp -f ${srcdir}/dest/usr/share/man/man1/${ff}.1 ${pkgdir}/usr/share/man/man1/${ff}.1
  done
  cp -f ${srcdir}/dest/usr/share/man/man5/info.5 ${pkgdir}/usr/share/man/man5/info.5
  cp -f ${srcdir}/dest/usr/share/info/info.info ${pkgdir}/usr/share/info/info.info
  cp -f ${srcdir}/dest/usr/share/info/info-stnd.info ${pkgdir}/usr/share/info/info-stnd.info
}

package_texinfo-tex() {
  depends=('perl' 'sh')
  groups=('base-devel')

  mkdir -p ${pkgdir}/usr/{bin,share}
  mkdir -p ${pkgdir}/usr/share/man/man1
  for ff in texindex texi2dvi texi2pdf pdftexi2dvi; do
    cp -f ${srcdir}/dest/usr/bin/${ff} ${pkgdir}/usr/bin/${ff}
    cp -f ${srcdir}/dest/usr/share/man/man1/${ff%.*}.1 ${pkgdir}/usr/share/man/man1/${ff%.*}.1
  done
}
